import 'package:flutter/material.dart';
import 'package:hao_ke/utils/dio_http.dart';
import 'package:hao_ke/pages/utils/scoped_model_helper.dart';
import '../pages/auth/auth.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

class StoreWidget extends StatefulWidget {
  const StoreWidget({super.key});

  @override
  State<StoreWidget> createState() => _StoreWidgetState();
}

class _StoreWidgetState extends State<StoreWidget> {

  List<String> items = [];

  String storeId = '';

  @override
  Widget build(BuildContext context) {
    _getStore();
    return Container(
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [Text('$storeId'),TextButton(
                child: Text('选择门店'),
                onPressed: () {
                  TDPicker.showMultiPicker(context, title: '选择地区',
                      pickerHeight: 300,
                      onConfirm: (selected) {
                        setState(() {
                          storeId = '${items[selected[0]]}';
                        });
                      }, data: [items]);
                }
            )],
          ),
          Divider(height: 0.1,color: Colors.white,),
        ]
      )
    );
  }


  _getStore() async {
    var storeList = await DioHttp().init(context, ScopedModelHelper.getModel<AuthModel>(context).token).get("/uc/store/");
    setState(() {
      items = [];
      storeList.forEach((element) {
        items.add( element['name'].toString());
      });
    });
  }
}
